
export function getRouter(menuList = []) {
    const routers = []
    menuRecursion(menuList, routers)
    
    return routers;
}
 
// 递归设置路由信息
function menuRecursion(menus = [], routers = []) {
    menus.forEach((menu,index) => {
        // console.log(menu)
      
        const route = getRealRoute(menu);
        routers.push(route)
        if(menu.children.length !== 0){
            const children = menu.children;
            // 递归实现
            menuRecursion(children, routers[index].children)

        }
    })
}
 
const modules = import.meta.glob('../../app/*/views/**/*.vue')


/**
 * 获取路由标准
 */
function getRealRoute(item) {

    // 路由基本格式
    return {
        // 路由的路径
        path: item.route,
        
        // 路由名
        name: item.permission_name,

        // a:`@/app${item.component}.vue`,
        // 路由所在组件
        // component: item.component ? resolve => import(/* @vite-ignore */`/app${item.component}.vue`):'',
        component:  modules[`../../app/${item.component}.vue`],
        meta: {
            id: item.id,
            icon: item.icon,
            path:item.route,
            title:item.permission_name
        },
        
        // 路由的子路由
        children: []
    }
}